package com.ts.code.creator.creator;

import com.intellij.psi.PsiJavaFile;
import com.ts.code.creator.util.CreateCodeContext;
import com.ts.code.creator.util.StringUtil;

public class ClassFileSearch {

    private CreateCodeContext context;
    private String basePath;

    public ClassFileSearch(CreateCodeContext context) {
        this.context = context;
        this.basePath = context.getProject().getBasePath();
    }

    public String adminController() {
        PsiJavaFile adminControllerFile = context.getAdminControllerFile();
        return adminControllerFile.getVirtualFile().getPath();
    }

    public String adminService() {
        String parentDir = context.getAdminControllerFile().getVirtualFile().getParent().getParent().getPath();
        return parentDir + "/service/" + context.getEntityAlias() + "Service.java";
    }

    public String adminServiceImpl() {
        String parentDir = context.getAdminControllerFile().getVirtualFile().getParent().getParent().getPath();
        return parentDir + "/service/impl/" + context.getEntityAlias() + "ServiceImpl.java";
    }

    public String providerInterface() {
        return basePath + "/cloud-provider/src/main/java/com/tiansheng/cloud/provider/" + context.getServiceAlias() + "/contract/"
                + context.getEntityAlias() + "Interface.java";
    }

    public String serviceController() {
        return basePath + "/" + context.getService() + "/src/main/java/com/tiansheng/cloud/service/" + context.getServiceAlias()
                + "/controller/" + context.getEntityName() + "Controller.java";
    }

    public String serviceService() {
        return basePath + "/" + context.getService() + "/src/main/java/com/tiansheng/cloud/service/" + context.getServiceAlias()
                + "/service/" + context.getEntityName() + "Service.java";
    }

    public String serviceServiceImpl() {
        return basePath + "/" + context.getService() + "/src/main/java/com/tiansheng/cloud/service/" + context.getServiceAlias()
                + "/service/impl/" + context.getEntityName() + "ServiceImpl.java";
    }

    public String adminVO() {
        String parentDir = context.getAdminControllerFile().getVirtualFile().getParent().getParent().getPath();
        return parentDir + "/vo/" + classFile("VO");
    }

    public String adminVODir() {
        String parentDir = context.getAdminControllerFile().getVirtualFile().getParent().getParent().getPath();
        return parentDir + "/vo";
    }

    public String adminParam() {
        String parentDir = context.getAdminControllerFile().getVirtualFile().getParent().getParent().getPath();
        return parentDir + "/param/" + classFile("Param");
    }

    public String adminParamDir() {
        String parentDir = context.getAdminControllerFile().getVirtualFile().getParent().getParent().getPath();
        return parentDir + "/param";
    }

    public String adminPackage() {
        PsiJavaFile adminControllerFile = context.getAdminControllerFile();
        String packageName = adminControllerFile.getPackageName();
        return packageName.substring(0, packageName.lastIndexOf("."));
    }

    public String providerReqDTO() {
        return basePath + "/cloud-provider/src/main/java/com/tiansheng/cloud/provider/" + context.getServiceAlias() + "/dto/"
                + classFile("ReqDTO");
    }

    public String providerDTODir() {
        return basePath + "/cloud-provider/src/main/java/com/tiansheng/cloud/provider/" + context.getServiceAlias() + "/dto";
    }

    public String providerDTOPackage() {
        return "com.tiansheng.cloud.provider." + context.getServiceAlias() + ".dto";
    }

    public String providerRespDTO() {
        return basePath + "/cloud-provider/src/main/java/com/tiansheng/cloud/provider/" + context.getServiceAlias() + "/dto/"
                + classFile("RespDTO");
    }

    public String classFile(String suffix) {
        return className(suffix) + ".java";
    }

    public String className(String suffix) {
        return context.getEntityAlias() + StringUtil.firstUpper(context.getMethodName()) + suffix;
    }

}
